import axios from './config'

//页面接口通用接口 get
export function ajaxGet(url = '', data = {}, option = {}, isMock) {
 
	return axios.get(url,data).then((result)=>{
        console.log('axios',result,result.data,result.data.code,result.data.code==200)
        // if(result.data.code == 200){
          return Promise.resolve(result.data);
        // };
	}).catch((result)=>{
	})
}
//页面接口通用接口 Post
export function ajaxPost(url = '', data = {}, option = {}, uid = '', token = '') {

  // 调用函数
  if(uid) {
    axios.defaults.headers['uid'] = uid
  }
  if(token) {
    axios.defaults.headers['Authorization'] = token
  }
  if(option.contentType) axios.defaults.headers['Content-Type'] = option.contentType;
  else axios.defaults.headers['Content-Type'] = 'application/json';
  // ,multipart/form-data
  axios.defaults.dataType = 'jsonp';

	return axios.post(url, data, option).then(result => {
    // if(result.data.code == 200||result.data.meta.code == 6666){
      return Promise.resolve(result.data);
    // }
	}).catch(res => {
	})
}


var _HOST
console.log(process.env.NODE_ENV, 'process.env.NODE_ENV')
console.log(window.global_url,'window.global_url1')
_HOST = window.global_url._HOST
//接口请求地址
// if (process.env.NODE_ENV === 'prod') {
//   _HOST = 'https://192.172.50.84:5111'//线上环境

// } else if (process.env.NODE_ENV === 'uat') {
//   _HOST = 'https://192.172.2.6:5111'//uat

// } else if (process.env.NODE_ENV === 'test') {
//   _HOST = 'https://192.172.9.149:5001'       // 测试环境
  
// } else {
//   _HOST = 'https://192.172.2.6:5111'       // 开发环境
// }

export function getUrl(){
  return _HOST
}

export function uploadFile(data){
  return ajaxPost(`${_HOST}/api/Upload`,data)
}

export function getUploadImage(data){
  return ajaxPost(`${_HOST}/api/CorrectImage`,data)
}

export function getUpCode(data){
  return ajaxPost(`${_HOST}/api/Queue`,data)
}
export function getParams(){
  return ajaxPost(`${_HOST}/api/Menu`)
}
export function downLoadFile(url){
  return ajaxGet(`${_HOST}/api/Download?filePath=${url}`)
}
